<include file="Common/header" />
<!-- 导航栏 -->
{$bread_crumb}
<!-- 导航栏 -->
<div class="page-container">
    <!-- 搜索 -->
    <!-- <div class="text-c">
        <form action="{:U(CONTROLLER_NAME.'/index')}" method="get">
            <input type="text" class="input-text" style="width:80px" placeholder="编号" name="id" value="{$id}">
            <input type="text" class="input-text" style="width:80px" placeholder="字符串" name="varchar" value="{$varchar}">
            日期范围：<input type="text" name="datetime_start" value="{$datetime_start}" onfocus="WdatePicker()" class="input-text Wdate" style="width:120px;"> - 
            <input type="text" name="datetime_end" value="{$datetime_end}" onfocus="WdatePicker()" class="input-text Wdate" style="width:120px;">
            <button type="submit" class="btn btn-success radius"><i class="Hui-iconfont">&#xe665;</i>搜索</button>
        </form>
    </div> -->
    <!-- 操作 -->
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <a class="btn btn-primary radius" onclick="add('添加','{:U(CONTROLLER_NAME.'/add')}')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加角色</a>
        </span> 
        <span class="r">共有数据：<strong>{$count}</strong> 条</span> 
    </div>
    <div class="mt-20 dataTables_wrapper">
    <table class="table table-border table-bordered table-hover table-bg table-sort">
        <thead>
            <tr class="text-c">
                <th>编号</th>
                <th>组名</th>
                <th>描述</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <foreach name="datas" item="item">
                <tr class="text-c">
                    <td>{$item.id}</td>
                    <td>{$item.title}</td>
                    <td>{$item.description}</td>
                    <td class="td-manage">
                        <a style="text-decoration:none" class="ml-5" onClick="update('编辑','{:U(CONTROLLER_NAME.'/update')}','{$item.id}')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>

                        <a style="text-decoration:none" class="ml-5" onClick="del(this,'{$item.id}')" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>
                    </td>
                </tr>
            </foreach>
        </tbody>
    </table>
    {$pages}
</div>
<include file="Common/footer" />
<script type="text/javascript">
/*添加*/
function add(title,url){
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}
/*编辑*/
function update(title,url,id){
    var index = layer.open({
        type: 2,
        title: title,
        content: url + '?id=' + id,
    });
    layer.full(index);
}
/*删除*/
function del(obj,id){
    layer.confirm('确认要删除吗？',function(index){
        $.ajax({
            type: 'POST',
            url: '{:U(CONTROLLER_NAME.'/delete')}',
            data: {id: id},
            dataType: 'json',
            success: function(data){
                if (data.code == 0) {
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!',{icon:1,time:1000});
                } else {
                    layer.msg(data.msg,{icon:2,time:1000});
                }
            },
            error: function(data) {
                console.log(data.msg);
            },
        });     
    });
}
/*删除所选*/
function del_select() {
    var arr = []
        ids = '';
    $('.select:checkbox:checked').each(function() {
        arr.push($(this).val());
    });

    ids = arr.join(',');
    layer.confirm('确认要删除吗？',function(index){
        $.ajax({
            type: 'POST',
            url: '{:U(CONTROLLER_NAME.'/delete')}',
            data: {id: ids},
            dataType: 'json',
            success: function(data){
                if (data.code == 200) {
                    layer.msg('已删除!',{icon:1,time:1000});
                    window.location.reload();
                } else {
                    layer.msg(data.msg,{icon:2,time:1000});
                }
            },
            error: function(data) {
                console.log(data.msg);
            },
        });
    });
}
</script> 